import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-12
 * Time: 19:49
 */
//https://leetcode.cn/problems/move-zeroes/
public class Test {
    public static void moveZeroes(int[] nums) {
        int p1=0;
        int p2=0;
        int n;
        while(p2<nums.length){
            while(p1<nums.length&&nums[p1]!=0){
                p1++;
            }
            if(p1>=nums.length){
                break;
            }
            while(p2<nums.length&&(nums[p2]==0||p2<p1)){
                p2++;
            }
            if(p2>=nums.length){
                break;
            }
            n=nums[p1];
            nums[p1]=nums[p2];
            nums[p2]=n;
            p1++;
            p2++;
        }
    }
    public static void main(String[] args) {
        int[] arr={0,1,0,3,12};
        moveZeroes(arr);
        System.out.println(Arrays.toString(arr));

    }
}
